<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    if ( ! function_exists('isLoggedWithCookie'))
    {
            function isLoggedWithCookie()
            {
                $ci = &get_instance();
                $ci->load->helper("cookie");
                return get_cookie("auth_id") && get_cookie("auth_passwd");
            }
    }
    
    if ( ! function_exists('isLogged'))
    {
            function isLogged($login = "", $passwd = "")
            {
                $ci = &get_instance();
                $ci->load->model("user_model");
                if($login == "" || $passwd == ""):
                    if($ci->session->userdata("auth_id") && $ci->session->userdata("auth_passwd")) :
                        return $ci->employe_model->login($ci->session->userdata("auth_id"), $ci->session->userdata("auth_passwd"));
                    else:
                        return _loginCookie();
                    endif;
                else:
                    return $ci->employe_model->login($login, $passwd);
                endif;
            }
    }
    
    if ( ! function_exists('_loginCookie'))
    {
            function _loginCookie()
            {
                $ci = &get_instance();
                $ci->load->helper("cookie");
                $identifiant = get_cookie("auth_id");
                $password = get_cookie("auth_passwd");
                if($identifiant && $password) :
                    if($ci->employe_model->login($identifiant, $password)):
                        $ci->session->set_userdata(array('auth_id' => $identifiant, 'auth_passwd' => $password));
                        return true;
                    endif;
                else:
                    return false;
                endif;
            }
    }

?>

